﻿/*
 * Copyright (C) 2012 TheLionsRoar <thelionwillalwaysroar@gmail.com>
 * Copyright (C) 2012 Jedrix <jedrix2454@gmail.com>
 * 
 * This file is part of the LEO Game Library.
 * 
 * LEO is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * LEO is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have receieved a copy of the GNU General Public License
 * along with LEO. If not, see <http://www.gnu.org/licenses/>.
 */
using System;
using Microsoft.Xna.Framework;

namespace LEO.Framework {
    public partial class GameObject : Drawable {
        public enum Direction {
            North,
            South,
            East,
            West,
        }

        private Vector2 velocity;
        private float speed;
        private bool solid;
        private bool blocksVision;

        public Vector2 Velocity {
            get { return velocity; }
            set {
                velocity = value;
                if(velocity != Vector2.Zero) {
                    velocity.Normalize();
                }
            }
        }

        public float Speed {
            get { return speed; }
            set { speed = value; }
        }

        public bool Solid {
            get { return solid; }
            set { solid = value; }
        }

        public bool BlocksVision {
            get { return blocksVision; }
            set { blocksVision = value; }
        }

        public GameObject(Sprite sprite, Vector2 position, float movespeed = 0, bool issolid = false, bool blockvision = false) {
            Sprite = sprite;
            Position = position;
            Speed = movespeed;
            Solid = issolid;
            BlocksVision = blockvision;
        }

        public virtual void Move(Direction direction) {
            Vector2 movement = new Vector2();
            switch(direction) {
                case Direction.North:
                    movement.Y -= speed * Time.DeltaTime;
                    break;

                case Direction.South:
                    movement.Y += speed * Time.DeltaTime;
                    break;

                case Direction.East:
                    movement.X += speed * Time.DeltaTime;
                    break;

                case Direction.West:
                    movement.X -= speed * Time.DeltaTime;
                    break;
            }

            Position += movement;
        }

        public override void Update(GameTime gameTime) {
            Position += Velocity;
            Sprite.Update(gameTime);
            base.Update(gameTime);
        }
    }
}
